﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace CypherBox
{
    class XMLSerializing
    {
        public static void Serialize<T>(string path, T data)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            TextWriter textWriter = new StreamWriter(path);
            serializer.Serialize(textWriter, data);
            textWriter.Close();
        }
        public static T Deserialize<T>(string path)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException(path+" not found");
            }
            XmlSerializer deserializer = new XmlSerializer(typeof(T));
            TextReader textReader = new StreamReader(path);
            T data = (T)deserializer.Deserialize(textReader);
            textReader.Close();
            return data;
        }
    }
}
